#include <string>
#include <iostream>

using namespace std;

/*
给定一个由小写字母组成的字符串 s，接下来我们要对 s 执行下面这样的压缩算法：

* “aaaaa” => "5a"
* "aaabbbccc" => "3a3b3c"
* "ddddddddd" => "9d"
* "dddddddddd" => "9d1d"
* "dddddddddddd" => "9d3d"
* "ccccccccccc" => "9c2c"
* "xyz" => "1x1y1z"
* "ab...bccc" => "1a9b3b3c"
*/

// compressor("aaaaa") => "5a"
// compressor("aaabbbccc") => "3a3b3c"
// compressor("") => ""

// int len = 3; 3a 3b 3c

// s: a a a b b b c c c
//        i i+1
// s[i] == s[i + 1]
string compressor(const string &s) {
  if (s.size() == 0) { return ""; }
  
  int len = 1;
  string result;

  for (int i = 0; i <= s.size() - 2; ++i) {
    char curr = s[i];
    char next = s[i + 1];

    if (curr == next) {
      ++len;
    }
    else {
      // 把 len 转换成 string
      // 把 len 拼接到 result 末尾
      // 把 curr 拼接到 result 末尾
      result += to_string(len);
      result.push_back(curr);

      len = 1;
    }
  }

  result += to_string(len);
  result.push_back(s.back());

  return result;
}

int main(int argc, char const *argv[])
{
  /* code */
  return 0;
}
